package test_public;

import org.junit.Assert;
import org.junit.Test;

import queenProblem.QueenProblemSolver;

public class QueenProblemSutdentsTest {

	boolean[][] field;
	
	QueenProblemSolver solver;
	
	@Test
	public void test_field1x1() {
		field = new boolean[1][1];
		solver = new QueenProblemSolver(field, 0);
		
		Assert.assertTrue(solver.solve());
	}
	
	@Test
	public void test_field2x2() {
		field = new boolean[2][2];
		solver = new QueenProblemSolver(field, 0);
		
		Assert.assertFalse(solver.solve());
		Assert.assertArrayEquals(new boolean[2][2], solver.getPlayField());
	}
	
	@Test
	public void test_field3x3() {
		field = new boolean[3][3];
		solver = new QueenProblemSolver(field, 0);
		
		Assert.assertFalse(solver.solve());
		Assert.assertArrayEquals(new boolean[3][3], solver.getPlayField());
		
	}
	
	@Test
	public void test_field4x4_diagonal() {
		field = new boolean[4][4];
		field[0][0] = true;
		field[1][1] = true;
		field[2][2] = true;
		
		solver = new QueenProblemSolver(field, 0);
		
		Assert.assertFalse(solver.solve());
		
		for(int row = 0; row < 4; row++) {
			for(int column = 0; column < 4; column++) {
				if(row == column && row != 3) {
					Assert.assertTrue(field[row][column]);
				} else {
					Assert.assertFalse(field[row][column]);
				}
			}
		}
	}
	
	@Test
	public void test_field4x4_row() {
		field = new boolean[4][4];
		field[0][0] = true;
		field[0][1] = true;
		field[0][2] = true;
		field[0][3]	= true;
		
		solver = new QueenProblemSolver(field, 0);
		
		Assert.assertFalse(solver.solve());
		
		for(int row = 0; row < 4; row++) {
			for(int column = 0; column < 4; column++) {
				if(row == 0) {
					Assert.assertTrue(field[row][column]);
				} else {
					Assert.assertFalse(field[row][column]);
				}
			}
		}
	}
	
	@Test
	public void test_field4x4() {
		field = new boolean[4][4];
		solver = new QueenProblemSolver(field, 0);
		
		Assert.assertTrue(solver.solve());
		Assert.assertTrue(field[0][1]);
		Assert.assertTrue(field[1][3]);
		Assert.assertTrue(field[2][0]);
		Assert.assertTrue(field[3][2]);
	}
	
	@Test
	public void test_field4x4_withQueen() {
		field = new boolean[4][4];
		field[0][2] = true;
		solver = new QueenProblemSolver(field, 0);
		
		Assert.assertTrue(solver.solve());
		Assert.assertTrue(field[0][2]);
		Assert.assertTrue(field[1][0]);
		Assert.assertTrue(field[2][3]);
		Assert.assertTrue(field[3][1]);
	}
	
	@Test
	public void test_field8x8_empty() {
		field = new boolean[8][8];
		solver = new QueenProblemSolver(field, 0);
		
		Assert.assertTrue(solver.solve());
		Assert.assertTrue(field[0][0]);
		Assert.assertTrue(field[1][6]);
		Assert.assertTrue(field[2][3]);
		Assert.assertTrue(field[3][5]);
		Assert.assertTrue(field[4][7]);
		Assert.assertTrue(field[5][1]);
		Assert.assertTrue(field[6][4]);
		Assert.assertTrue(field[7][2]);
	}
}
